<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/19
 * Time: 22:28
 */

namespace app\api\validate;

class IdCollection extends BaseValidate
{
    protected $rule = [
        'id' => 'require|isPositiveInt',
    ];
    protected $message = [
        'id.require' => '必须存在',
        'id.isPositiveInt' => '必为整数',
    ];
    //定义判断是否为整数的验证
    protected function isPositiveInt($value)
    {
        if(empty($value)) return false;
        $value = explode(',', $value);
        foreach ($value as $id) {
            if(!$this -> isPositiveInteger($id)) return false;
        }
        return true;
    }
}